#include <bits/stdc++.h>
#include <string>
#include <queue>
using namespace std;

/** 队列结构体 */
struct Queue
{
    int *list;    // 队列的列表
    int capacity; // 队列最大容量
    int head;     // 头指针
    int rear;     // 尾指针
};

/** 初始化队列 */
struct Queue initQueue(struct Queue q, int capacity)
{
    q.head = q.rear = 0;
    q.capacity = capacity;
    q.list = (int *)malloc(sizeof(int) * (capacity + 1));
    return q;
}

/** 判断队列是否为空 */
bool isQueueEmpty(struct Queue q)
{
    return q.rear == q.head;
}

/** 判断队列是否为满 */
bool isQueueFull(struct Queue q)
{
    return (q.rear + 1) % (q.capacity + 1) == q.head;
}

/** 入队 */
struct Queue enQueue(struct Queue q, int val)
{
    if(isQueueFull(q)) return q;
    q.list[q.rear] = val;
    q.rear++;
    q.rear %= (q.capacity + 1);
    return q;
}

/** 出队 */
int deQueue(struct Queue *q)
{
    if(isQueueEmpty(*q)) return -INT_MAX;
    int count = q->list[q->head];
    q->head++;
    q->head %= (q->capacity + 1);
    return count;
}

/** 打印队列的每个元素 */
void printQueue(const struct Queue q)
{
    int h = q.head, r = q.rear;
    while (h != r)
    {
        cout << q.list[h] << " ";
        h++;
        h %= (q.capacity + 1);
    }
    cout << endl;
}

int main()
{

    struct Queue q;
    q = initQueue(q, 5);
    q = enQueue(q, 1);
    q = enQueue(q, 2);
    q = enQueue(q, 3);
    printQueue(q);
    cout << deQueue(&q) << endl;
    printQueue(q);
    q = enQueue(q, 4);
    q = enQueue(q, 5);
    q = enQueue(q, 6);
    cout << isQueueFull(q) << endl;
    return 0;
}